package com.dsz.apibackend.exception;

import com.dsz.apibackend.common.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自定义事务异常
 * @author dushangzhi
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BusinessException extends RuntimeException {
    /**
     * 错误码
     */
    private final int code;

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
    }

    public BusinessException(ErrorCode errorCode, String message) {
        super(message);
        this.code = errorCode.getCode();
    }
}
